package com.flurry.android;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.VideoView;
import java.util.Collections;

public final class FlurryFullscreenTakeoverActivity extends Activity
  implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener
{
  public static final String EXTRA_KEY_ADSPACENAME = "adSpaceName";
  public static final String EXTRA_KEY_FRAMEINDEX = "frameIndex";
  public static final String EXTRA_KEY_TARGETINTENT = "targetIntent";
  public static final String EXTRA_KEY_URL = "url";
  private static final String p = FlurryFullscreenTakeoverActivity.class.getSimpleName();
  private AdUnit T;
  private String dq;
  private long fA;
  private ft fr;
  private ViewGroup fs;
  private cf ft;
  private ProgressDialog fu;
  private VideoView fv;
  private boolean fw;
  private MediaController fx;
  private boolean fy;
  private Intent fz;

  private void aG()
  {
    if (this.fu != null)
    {
      if (this.fu.isShowing())
        this.fu.dismiss();
      this.fu = null;
    }
    if (this.ft != null)
      this.ft.setVisibility(0);
    if (this.fv != null)
    {
      if (this.fv.isPlaying())
        this.fv.stopPlayback();
      if (this.fs != null)
        this.fs.removeView(this.fv);
      this.fv = null;
    }
    this.fw = false;
    this.fx = null;
  }

  private static boolean t(String paramString)
  {
    boolean bool1 = TextUtils.isEmpty(paramString);
    boolean bool2 = false;
    if (!bool1)
    {
      String str = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(paramString));
      bool2 = false;
      if (str != null)
      {
        boolean bool3 = str.startsWith("video/");
        bool2 = false;
        if (bool3)
          bool2 = true;
      }
    }
    return bool2;
  }

  private void u(String paramString)
  {
    if ((TextUtils.isEmpty(paramString)) || (this.fv == null) || (this.fs == null));
    do
    {
      return;
      this.fx = new MediaController(this);
      this.fv.setOnPreparedListener(this);
      this.fv.setOnCompletionListener(this);
      this.fv.setOnErrorListener(this);
      this.fv.setMediaController(this.fx);
      this.fv.setVideoURI(Uri.parse(paramString));
      this.fs.addView(this.fv, new FrameLayout.LayoutParams(-1, -1, 17));
      this.fu = new ProgressDialog(this);
      this.fu.setProgressStyle(0);
      this.fu.setMessage("Loading...");
      this.fu.setCancelable(true);
      this.fu.show();
    }
    while (this.ft == null);
    this.ft.setVisibility(8);
  }

  final AdUnit L()
  {
    return this.T;
  }

  final ft aH()
  {
    return this.fr;
  }

  public final void onCompletion(MediaPlayer paramMediaPlayer)
  {
  }

  public final void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
  }

  public final void onCreate(Bundle paramBundle)
  {
    int i = -1;
    setTheme(16973831);
    super.onCreate(paramBundle);
    s.a(getWindow());
    Intent localIntent = getIntent();
    this.fz = ((Intent)localIntent.getParcelableExtra("targetIntent"));
    this.dq = localIntent.getStringExtra("adSpaceName");
    if (this.fz != null);
    while (true)
    {
      try
      {
        startActivity(this.fz);
        this.fA = SystemClock.elapsedRealtime();
        FlurryAds.getInstance().a(this);
        return;
      }
      catch (ActivityNotFoundException localActivityNotFoundException)
      {
        cy.b(p, "Cannot launch Activity", localActivityNotFoundException);
        this.fz = null;
        finish();
        continue;
      }
      String str = localIntent.getStringExtra("url");
      if (str == null)
      {
        this.fs = new RelativeLayout(this);
        if (paramBundle == null);
        while (true)
        {
          if (i < 0)
            i = localIntent.getIntExtra("frameIndex", 0);
          FlurryAds localFlurryAds = FlurryAds.getInstance();
          this.T = localFlurryAds.br();
          if (this.T == null)
            break;
          this.fr = new ft(this, localFlurryAds, localFlurryAds.bq(), this.T, i);
          this.fr.initLayout(this);
          RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
          localLayoutParams.addRule(13);
          this.fs.addView(this.fr, localLayoutParams);
          setContentView(this.fs);
          break;
          i = paramBundle.getInt("frameIndex", i);
        }
      }
      this.fs = new FrameLayout(this);
      setContentView(this.fs);
      if (t(str))
      {
        this.fv = new gk(this);
        u(str);
      }
      else
      {
        this.ft = new cf(this, str);
        this.ft.a(new h(this));
        this.ft.a(new ee(this));
        this.ft.a(new aq(this));
        this.fs.addView(this.ft);
      }
    }
  }

  protected final void onDestroy()
  {
    aG();
    if (this.ft != null)
      this.ft.destroy();
    if (this.fr != null)
      this.fr.stop();
    FlurryAds.getInstance().b(this);
    super.onDestroy();
  }

  public final boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
  {
    cy.d(p, "error occurs during video playback");
    if (this.ft != null)
      if (this.fw)
        if (this.ft.canGoBack())
        {
          this.ft.goBack();
          aG();
        }
    while (true)
    {
      return true;
      finish();
      continue;
      aG();
      continue;
      finish();
    }
  }

  public final boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 4)
    {
      if (this.fr != null)
      {
        this.fr.a("adWillClose", Collections.emptyMap(), this.fr.T, this.fr.S, this.fr.U, 0);
        return true;
      }
      if (this.fv != null)
      {
        if (this.ft != null)
          if (this.fw)
          {
            if (this.ft.canGoBack())
            {
              this.ft.goBack();
              aG();
              return true;
            }
          }
          else
          {
            aG();
            return true;
          }
      }
      else if ((this.ft != null) && (this.ft.canGoBack()))
      {
        this.ft.goBack();
        return true;
      }
    }
    return super.onKeyUp(paramInt, paramKeyEvent);
  }

  protected final void onPause()
  {
    super.onPause();
    this.fy = false;
    if ((this.fv != null) && (this.fv.isPlaying()))
      this.fv.pause();
    if (this.fr != null)
      this.fr.pause();
  }

  public final void onPrepared(MediaPlayer paramMediaPlayer)
  {
    if ((this.fu != null) && (this.fu.isShowing()))
      this.fu.dismiss();
    if ((this.fv != null) && (this.fy))
      this.fv.start();
  }

  protected final void onRestart()
  {
    super.onRestart();
  }

  protected final void onResume()
  {
    super.onResume();
    this.fy = true;
    if (this.fx != null)
      this.fx.show(0);
    if (this.fr != null)
      this.fr.resume();
  }

  public final void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if (this.fr != null)
      paramBundle.putInt("frameIndex", this.fr.U);
  }

  public final void onStart()
  {
    super.onStart();
    if (FlurryAgent.y() != null)
    {
      FlurryAgent.onStartSession(this, FlurryAgent.y());
      return;
    }
    finish();
  }

  public final void onStop()
  {
    FlurryAgent.onEndSession(this);
    super.onStop();
  }

  public final void onWindowFocusChanged(boolean paramBoolean)
  {
    new StringBuilder().append("onWindowFocusChanged hasFocus = ").append(paramBoolean).toString();
    if ((this.fy) && (paramBoolean) && (this.fz != null) && (SystemClock.elapsedRealtime() - this.fA > 250L))
      finish();
    super.onWindowFocusChanged(paramBoolean);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.flurry.android.FlurryFullscreenTakeoverActivity
 * JD-Core Version:    0.6.2
 */